using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VMEVAR
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {
            #region
            #endregion
            switch (app.company)
            {
                case "YGR":
                case "SXN":
                case "TST":
                case "UBT":
                default:
                    #region
                    dwReturn["MEVMANDANT"] = "00";
                    dwReturn["MEVAGANG"] = "MM             ";
                    dwReturn["MEVMTYP"] = "MMJY    ";
                    dwReturn["MEVMNRKRS"] = "  ";
                    dwReturn["MEVMLFDNR"] = "0641";
                    dwReturn["MEVMPOS"] = "00";
                    dwReturn["MEVEVARHNR"] = "01";
                    dwReturn["MEVEVARUNR"] = "01";
                    dwReturn["MEVMODNR"] = "010";
                    dwReturn["MEVEINSTNR"] = "010";
                    dwReturn["MEVWERTX"] = "1               ";
                    dwReturn["MEVWERTN"] = "0000000000000000";
                    dwReturn["MEVPROGNR"] = "0000";
                    dwReturn["MEVEINAUS"] = " ";
                    dwReturn["MEVREZEPTNR"] = "          ";
                    dwReturn["MEVREZEPTKZ"] = " ";
                    dwReturn["MEVREZEPTST"] = "0";
                    dwReturn["MEVWERKZ"] = "              ";
                    dwReturn["MEVFAKTOR"] = "00";
                    dwReturn["MEVSTAKZ"] = " ";
                    dwReturn["MEVMODEIN"] = " ";
                    dwReturn["MEVAENDZL"] = "0";
                    dwReturn["MEVAENDBEN"] = "        ";
                    dwReturn["MEVAENDDAT"] = "0";
                    dwReturn["MEVNEUBEN"] = "LZH     ";
                    dwReturn["MEVNEUDAT"] = "20140708";
                    dwReturn["MEVFILLER"] = "                ";
                    #endregion
                    break;
            }
        }

        public void InsertMEVAR(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            switch (app.company)
            {
                case "YGR":
                case "SXN":
                case "TST":
                case "UBT":
                default:
                    or1.CommandText = "INSERT INTO MEVAR ( MEVMANDANT,MEVAGANG,MEVMTYP,MEVMNRKRS,MEVMLFDNR,MEVMPOS,MEVEVARHNR,MEVEVARUNR,MEVMODNR,MEVEINSTNR,MEVWERTX,MEVWERTN,MEVPROGNR,MEVEINAUS,MEVREZEPTNR,MEVREZEPTKZ,MEVREZEPTST,MEVWERKZ,MEVFAKTOR,MEVSTAKZ,MEVMODEIN,MEVAENDZL,MEVAENDBEN,MEVAENDDAT,MEVNEUBEN,MEVNEUDAT,MEVFILLER)"
                    + " VALUES (:MEVMANDANT:,:MEVAGANG:,:MEVMTYP:,:MEVMNRKRS:,:MEVMLFDNR:,:MEVMPOS:,:MEVEVARHNR:,:MEVEVARUNR:,:MEVMODNR:,:MEVEINSTNR:,:MEVWERTX:,:MEVWERTN:,:MEVPROGNR:,:MEVEINAUS:,:MEVREZEPTNR:,:MEVREZEPTKZ:,:MEVREZEPTST:,:MEVWERKZ:,:MEVFAKTOR:,:MEVSTAKZ:,:MEVMODEIN:,:MEVAENDZL:,:MEVAENDBEN:,:MEVAENDDAT:,:MEVNEUBEN:,:MEVNEUDAT:,:MEVFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QMER01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT M.* FROM  MEVAR M"
                            + " WHERE MEVMANDANT=:MEVMANDANT: AND MEVAGANG=:MEVAGANG:  AND  MEVMTYP=:MEVMTYP:  AND  MEVMNRKRS=:MEVMNRKRS:  AND MEVMLFDNR=:MEVMLFDNR:  AND  MEVMPOS=:MEVMPOS:  AND MEVEVARHNR=:MEVEVARHNR:  AND  MEVEVARUNR=:MEVEVARUNR:  AND MEVMODNR=:MEVMODNR: AND MEVEINSTNR=:MEVEINSTNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QMER02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT MEVEINSTNR AS KEY, MEVEINSTNR AS DES,AMEMESCHL,AMEKBEZ,M.* FROM  MEVAR M"
                 + " JOIN MEKOPF ON MEKMANDANT = MEVMANDANT AND MEVMNRKRS=MEKMNRKRS AND MEKMLFDNR=MEVMLFDNR AND MEKMPOS=MEVMPOS AND MEKAGANG = MEVAGANG AND MEVMTYP = MEKMTYP AND MEVEVARHNR = MEKEVARHNR AND MEVEVARUNR = MEKEVARUNR"
                + " JOIN AMSTAMM ON AMMANDANT = MEVMANDANT AND MEKMNRKRS = AMKSTKRS AND MEKMLFDNR = AMKST AND AMTYP = MEKMTYP AND AMSTDVAR = 'J'"
                        + " JOIN AMEINST ON AMEMANDANT = AMMANDANT AND AMENRKRS = AMNRKRS AND AMLFDNR = AMELFDNR AND AMEPOS = AMPOS  AND MEVMODNR = AMEMODNR AND MEVEINSTNR = AMEEINSTNR"
                            + " WHERE MEVMANDANT=:MEVMANDANT:  "
                            + dwData["MEVAGANG"].ToString()
                            + dwData["MEVMTYP"].ToString()
                            + dwData["MEVMNRKRS"].ToString()
                            + dwData["MEVMLFDNR"].ToString()
                            + dwData["MEVMPOS"].ToString()
                            + dwData["MEVEVARHNR"].ToString()
                            + dwData["MEVEVARUNR"].ToString()
                            + dwData["MEVMODNR"].ToString()
                            + dwData["MEVEINSTNR"].ToString();
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public void DMER00(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEVAR"
                            + " WHERE MEVMANDANT=:MEVMANDANT:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
        public void DMER01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEVAR "
                            + " WHERE MEVMANDANT=:MEVMANDANT: AND MEVAGANG=:MEVAGANG:  AND  MEVMTYP=:MEVMTYP:  AND  MEVMNRKRS=:MEVMNRKRS:  AND MEVMLFDNR=:MEVMLFDNR:  AND  MEVMPOS=:MEVMPOS:  AND MEVEVARHNR=:MEVEVARHNR:  AND  MEVEVARUNR=:MEVEVARUNR:  AND MEVMODNR=:MEVMODNR: AND MEVEINSTNR=:MEVEINSTNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
        public void DMER02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEVAR"
                            + " WHERE MEVMANDANT=:MEVMANDANT: AND MEVAGANG=:MEVAGANG:  AND  MEVMTYP=:MEVMTYP:  AND  MEVMNRKRS=:MEVMNRKRS:  AND MEVMLFDNR=:MEVMLFDNR:  AND  MEVMPOS=:MEVMPOS:  AND MEVEVARHNR=:MEVEVARHNR:  AND  MEVEVARUNR=:MEVEVARUNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
        public void DMER03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEVAR"
                            + " WHERE MEVMANDANT=:MEVMANDANT: AND MEVAGANG=:MEVAGANG:  AND  MEVMTYP=:MEVMTYP:  ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }

        public void UpdateMEVAR(DataRow dwData, int option = 1)
        {
            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                    case "YGR":
                    case "SXN":
                    case "TST":
                    case "UBT":
                        UMER01(dwData); break;
                }
            }
        }
        public void UMER01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE MEVAR SET MEVMANDANT=:MEVMANDANT:,MEVAGANG=:MEVAGANG:,MEVMTYP=:MEVMTYP:,MEVMNRKRS=:MEVMNRKRS:,MEVMLFDNR=:MEVMLFDNR:,MEVMPOS=:MEVMPOS:,MEVEVARHNR=:MEVEVARHNR:,MEVEVARUNR=:MEVEVARUNR:,MEVMODNR=:MEVMODNR:,MEVEINSTNR=:MEVEINSTNR:,MEVWERTX=:MEVWERTX:,MEVWERTN=:MEVWERTN:,MEVPROGNR=:MEVPROGNR:,MEVEINAUS=:MEVEINAUS:,MEVREZEPTNR=:MEVREZEPTNR:,MEVREZEPTKZ=:MEVREZEPTKZ:,MEVREZEPTST=:MEVREZEPTST:,MEVWERKZ=:MEVWERKZ:,MEVFAKTOR=:MEVFAKTOR:,MEVSTAKZ=:MEVSTAKZ:,MEVMODEIN=:MEVMODEIN:,MEVAENDZL=:MEVAENDZL:,MEVAENDBEN=:MEVAENDBEN:,MEVAENDDAT=:MEVAENDDAT:,MEVNEUBEN=:MEVNEUBEN:,MEVNEUDAT=:MEVNEUDAT:,MEVFILLER=:MEVFILLER:"
             + " WHERE MEVMANDANT=:MEVMANDANT: AND MEVAGANG=:MEVAGANG:  AND  MEVMTYP=:MEVMTYP:  AND  MEVMNRKRS=:MEVMNRKRS:  AND MEVMLFDNR=:MEVMLFDNR:  AND  MEVMPOS=:MEVMPOS:  AND MEVEVARHNR=:MEVEVARHNR:  AND  MEVEVARUNR=:MEVEVARUNR:  AND MEVMODNR=:MEVMODNR: AND MEVEINSTNR=:MEVEINSTNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
    }
}
